<?php
require_once ('config.php');
require_once ('databasefunctions.php');
require_once ('displayfunctions.php');
require_once ('businessfunctions.php');
validate_user();

html_header();

$companyid = $_GET["companyid"];
$year = $_GET["year"];
$billno = $_GET["billno"];

if ($_GET["action"]=="save") {
    $duedate = $_GET["duedate"];
    $paymethod = $_GET["paymethod"];
    $reference = $_GET["reference"];
    $paydate = $_GET["paydate"];

    $updsql  = "REPLACE INTO `billdata` ";
    $updsql .= "( `CompanyID` , `Year` , `BillNo` , `DueDate` , `PayMethod` , `Reference` , `PayDate` ) ";
    $updsql .= "VALUES ";
    $updsql .= "('$companyid', '$year', '$billno', '$duedate' , '$paymethod', '$reference' , '$paydate') ";
    $result = sql_execute($updsql);
}

// Try to get bill data from database
$sql =  "SELECT * FROM `billdata` ";
$sql .= "WHERE CompanyID='$companyid'";
$sql .= "AND Year='$year'";
$sql .= "AND BillNo='$billno'";

$sql_result = sql_execute($sql);

$sql_data = mysql_fetch_array($sql_result);

?>

<SCRIPT LANGUAGE="JavaScript" ID="js1">
var cal1 = new CalendarPopup();
</SCRIPT>

<form method = "GET" action="bill_data.php" name = "transaction">
<input name="action" type="hidden" value="save">
<table>
<tr>
        <td bgcolor="<? echo $color1 ?>"><? echo $langcompanyid ?>
        <td><? echo $companyid ?><input name="companyid" type="hidden" value="<? echo $companyid ?>">
<tr>
        <td bgcolor="<? echo $color1 ?>"><? echo $langyear ?>
        <td><? echo $year ?><input name="year" type="hidden" value="<? echo $year ?>">
<tr>
        <td bgcolor="<? echo $color1 ?>"><? echo $langbillno ?>
        <td><? echo $billno ?><input name="billno" type="hidden" value="<? echo $billno ?>">
<tr>
        <td bgcolor="<? echo $color1 ?>"><? echo $langduedate ?>
        <td><input type = "text" name ="duedate" size = "10" maxlength="10"
             value="<? echo $sql_data['DueDate']?>">
            <A HREF="#" onClick="cal1.select(document.forms[0].duedate,'anchor1','yyyy-MM-dd'); return false;" TITLE="Date" NAME="anchor1" ID="anchor1">
            <img src="calendar.gif" border=0></A>
<tr>
        <td bgcolor="<? echo $color1 ?>"><? echo $langpaymethod ?>
        <td><input type = "text" name ="paymethod" size = "100" maxlength="255"
             value="<? echo $sql_data['PayMethod']?>">
<tr>
        <td bgcolor="<? echo $color1 ?>"><? echo $langreference ?>
        <td><input type = "text" name ="reference" size = "100" maxlength="100"
             value="<? echo $sql_data['Reference']?>">
<tr>
        <td bgcolor="<? echo $color1 ?>"><? echo $langpaydate ?>
        <td><input type = "text" name ="paydate" size = "10" maxlength="10"
             value="<? echo $sql_data['PayDate']?>">
            <A HREF="#" onClick="cal1.select(document.forms[0].paydate,'anchor1','yyyy-MM-dd'); return false;" TITLE="Date" NAME="anchor1" ID="anchor1">
            <img src="calendar.gif" border=0></A>
</td></tr></table>
<input type="submit" value="<? echo $langsave ?>">
</form>
<?

html_footer();
?>
